<template>
  <top-item title="今日订单" :value="numberFormat(orderToday)">
    <template #default>
      <div ref="order" id="order"></div>
    </template>
    <template #footer>
      <div class="footer">
        昨日订单量 <span>{{ numberFormat(orderLastDay) }}</span>
      </div>
    </template>
  </top-item>
</template>

<script setup lang="ts">
import { onMounted, watch, computed, ref } from 'vue'
import topItem from './top-item.vue'
import * as echarts from 'echarts'
import { useReportInfoData } from '@/stores/reportData'
import useFormat from '@/hooks/useFormat'
const { numberFormat, moneyFormat } = useFormat()
const reportInfoDataStore = useReportInfoData()

let orderChart: any

const orderToday = computed(() => reportInfoDataStore.reportData.orderToday)
const orderLastDay = computed(() => reportInfoDataStore.reportData.orderLastDay)
const orderTrend = computed(() => reportInfoDataStore.reportData.orderTrend)
const orderTrendAxis = computed(() => reportInfoDataStore.reportData.orderTrendAxis)

watch(() => reportInfoDataStore.reportData, () => {
  orderChart?.setOption({
    color: ['#80FFA5', '#00DDFF', '#37A2FF', '#FF0087', '#FFBF00'],
    grid: {
      left: 0,
      top: 0,
      right: 0,
      bottom: 0
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: false, // 两侧不留白
        data: orderTrendAxis.value,
        show: false
      }
    ],
    yAxis: [
      {
        type: 'value',
        show: false
      }
    ],
    series: [
      {
        name: '实时订单数',
        type: 'line',
        // stack: 'Total',
        smooth: true,
        lineStyle: {
          width: 0
        },
        showSymbol: false,
        areaStyle: { // 区域填充样式
          opacity: 0.8,
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: 'rgb(128, 255, 165)'
            },
            {
              offset: 1,
              color: 'rgb(1, 191, 236)'
            }
          ])
        },
        // 折线点样式
        itemStyle: {

        },
        emphasis: {
          focus: 'series'
        },
        data: orderTrend.value
      },
    ],
    tooltip: {
      trigger: 'axis',
      confine: true // 限定在固定区域显示提示
    }
  })

})
const order = ref()
onMounted(() => {
  orderChart = echarts.init(order.value as HTMLElement)

  window.addEventListener('resize', () => {
    orderChart?.resize()
  })
})



</script>

<style scoped>

</style>